<template>
	<view class="user_login">
		<image src="../../static/logo.png" mode="" class="user_pic"></image>
		<view class="login_btn">
			<button type="warn" @click="getUserInfo">一键登录</button>
		</view>
		<view class="login_text">
			登录后享更多权限
		</view>
	</view>
</template>

<script>
	export default {
		name: "ljy-login",
		data() {
			return {

			};
		},
		methods: {
			async getUserInfo() {
				let encryptedData = '';
				let rawData = '';
				let iv = '';
				let signature = '';
				let code = '';

				//获取用户信息
				const res = await uni.getUserProfile({
					desc: 'weixin',
				});
				console.log(res);
				encryptedData = res.encryptedData;
				rawData = res.rawData;
				iv = res.iv;
				signature = res.signature;
				uni.setStorageSync('userInfo', res.userInfo)

				//获取用户登录后的code
				const res1 = await uni.login();
				console.log(res1);
				code = res1.code;
				const LoginParams = {
					encryptedData,
					rawData,
					iv,
					signature,
					code
				};
				//发送请求获取用户的token
				// this.$Https({
				// 	url: '/users/wxlogin',
				// 	method: 'POST',
				// 	data: LoginParams
				// })

				// console.log(res2);
				// let token = res2.token;
				let token = 'token';
				uni.setStorageSync('token', token);
				let page = uni.getStorageSync('page');
				uni.removeStorageSync('page');
				if (page === 'pay') {
					uni.switchTab({
						url: '../../pages/pay/pay'
					})
				} else if (page === 'user') {
					uni.switchTab({
						url: '../../pages/user/user'
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	.user_login {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-top: 350rpx;
		justify-content: center;

		.user_pic {
			width: 25%;
			height: 180rpx;
			padding: 25rpx;
		}

		.login_text {
			font-size: 30rpx;
			padding: 10rpx;
			color: #848484;
		}

		.login_btn {
			width: 90%;
		}

		button {

			border-radius: 200rpx;
		}
	}
</style>
